package com.cwvs.cat.bean;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.cwvs.cat.Applications;


public class ClubTrends {
	public String id;
	public String sender;
	public String sendername;
	public String senderavatar;//20150410
	public String created;
	public String orderby;
	public String pic;
	public String content;
	public String status;
	public String goods_count;
	public String good_user;
	public String comment_count;
	public String comments;
	public JSONObject goodJsonObject = new JSONObject();
	public boolean zan = false;
	public String orderby_news_id;
	public boolean top = false;
	public ClubTrends(){

	}

	public ClubTrends(List<String> list) throws JSONException{
		this.id = list.get(0);
		this.sender = list.get(1);
		this.sendername = list.get(2);
		this.senderavatar = list.get(3);
		this.created = list.get(4);
		this.orderby = list.get(5);
		this.pic = list.get(6);
		this.content = list.get(7);
		this.status = list.get(8);
		this.goods_count = list.get(9);
		this.good_user = list.get(10).toString();
		if (!good_user.equals("null")&&!good_user.equals("")) {
			JSONObject	jsonObject = new JSONObject(list.get(10));
			goodJsonObject = jsonObject.getJSONObject("item");
			if (goodJsonObject.has(Applications.user.id)) {
				zan = true;
			}else {
				zan = false;
			}
		}
		this.comment_count = list.get(11);
		this.comments = list.get(12);
		if (list.size()==14) {
			this.orderby_news_id = list.get(13);
			if (orderby_news_id.equals(id)) {
				top = true;
			}
		}
	}
	
	public void fromJson(JSONObject json) throws JSONException{
		id = json.optString("id");
		sender = json.optString("sender");
		sendername = json.optString("sendername");
		senderavatar = json.optString("senderavatar");
		created = json.optString("created");
		orderby = json.optString("orderby");
		pic = json.optString("pic");
		content = json.optString("content");
		status = json.optString("status");
		goods_count = json.optString("goods_count");
		good_user = json.optString("good_user");
		if (!good_user.equals("null")&&!good_user.equals("")) {
			JSONObject	jsonObject = new JSONObject(good_user);
			goodJsonObject = jsonObject.getJSONObject("item");
			if (goodJsonObject.has(Applications.user.id)) {
				zan = true;
			}else {
				zan = false;
			}
		}
		comment_count= json.optString("comment_count");
		comments = json.optString("comments");
	}
	public JSONObject toJson(){
		JSONObject json = new JSONObject();
		try {
			json.put("id", id);
			json.put("sender", sender);
			json.put("sendername", sendername);
			json.put("senderavatar", senderavatar);
			json.put("created", created);
			json.put("orderby", orderby);
			json.put("pic", pic);
			json.put("content", content);
			json.put("status", status);
			json.put("goods_count", goods_count);
			json.put("good_user", good_user);
			json.put("comment_count", comment_count);
			json.put("comments", comments);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return json;
	}
	public static ClubTrends createFromJson(JSONObject json) throws JSONException {
		ClubTrends user = new ClubTrends();
		user.fromJson(json);
		return user;
	}
	
	
	
}
